const data = [
  {
    event_id: '1',
    type: '开课',
    title: 'aaa',
    content: 'aaa123',
    time: '2019.11.15',
    pic: '1.jpg',
    support: 'a',
    isCircle: 'a.jpg'
  },
  {
    event_id: '2',
    type: '比赛',
    title: 'bbb',
    content: 'bbb123',
    time: '2019.11.20',
    pic: '2.jpg',
    support: 'b',
    isCircle: 'b.jpg'
  }
]
export default [
  // 获取所有活动比赛信息
  {
    url: '/events',
    type: 'get',
    response: config => {
      return data
    }
  },
  // 添加活动比赛信息
  {
    url: '/event',
    type: 'post',
    response: config => {
      console.log(config.query)
      const { event_id, type, title, content, time, pic, support, isCircle } = config.body
      console.log(event_id + type + title + content + time + pic + support + isCircle)
      const person = { 'event_id': event_id, 'type': type, 'title': title, 'content': content, 'time': time, 'pic': pic, 'support': support, 'isCircle': isCircle }
      data.push(person)
      return (
        data
      )
    }
  },
  // 查找指定活动比赛信息
  {
    url: '/event',
    type: 'get',
    response: config => {
      const { path } = config
      const event_id = path.split('/')[3]
      var index
      for (var i in data) {
        if (data[i].event_id === event_id) {
          index = i
          break
        }
      }
      return (
        data[index]
      )
    }
  },
  // 修改活动比赛信息
  {
    url: '/event',
    type: 'put',
    response: config => {
      const { type, title, content, time, pic, support, isCircle } = config.body
      const { path } = config
      const event_id = path.split('/')[3]
      var index
      for (var i in data) {
        if (data[i].event_id === event_id) {
          index = i
          data[index].type = type
          data[index].title = title
          data[index].content = content
          data[index].time = time
          data[index].pic = pic
          data[index].support = support
          data[index].isCircle = isCircle
          break
        }
      }
      return (
        data[index]
      )
    }
  },
  // 删除指定用户
  {
    url: '/event',
    type: 'delete',
    response: config => {
      const { path } = config
      const event_id = path.split('/')[3]
      var index
      for (var i in data) {
        if (data[i].event_id === event_id) {
          index = i
          break
        }
      }
      data.splice(index, 1)
      return (
        data
      )
    }
  }
]
